import _, { includes, indexOf } from "lodash";
import $ from "jquery";

//印章添加，映射元素
let sealAddIdMapping = {
  sealAddNormal: "boxBtnSealAddNormal",
  sealAddContinued: "boxBtnSealAddContinued",
  sealAddBatch: "boxBtnSealAddBatch",
  sealAddGap: "boxBtnSealAddGap",
  sealAddByWord: "boxBtnSealAddByWord",
};

//印章其他功能，映射元素
let sealOthersIdMapping = {
  sealRemove: "boxBtnSealRemove",
  sealValidate: "boxBtnSealValidate",
};

//其他功能，映射元素
let othersIdMapping = {
  rotateRight: "boxPageRotateCw_mirror",
  find: "boxViewFind",
  download: "boxDownload",
  print: "boxPrint",
  thumbnail: "viewThumbnail",
  bookMark: "viewOutline",
};

//所有受控制的元素id
let idMapping = {
  ...sealAddIdMapping,
  ...sealOthersIdMapping,
  ...othersIdMapping,
  // seal: "boxBtnOfSeal",
  // siderMenuBar: "siderMenuBar",
};

export const editor = {
  initUI(toolsExcludes = []) {
    console.log("toolsExcludes", toolsExcludes);
    /** 关于签章功能项整合 */
    const sealMappingKeys = Object.keys({
      ...sealAddIdMapping,
      ...sealOthersIdMapping,
    });
    /** 是否展示盖章按钮的父级盒子 */
    let isShowSealBtnBox = false;
    /** 隐藏所有映射元素 */
    for (const idName in idMapping) {
      $("#" + idMapping[idName]).addClass("hidden");
    }
    /** 展示列表中映射存在的页面元素 */
    for (const toolName of toolsExcludes) {
      $("#" + idMapping[toolName]).removeClass("hidden");
      if (sealMappingKeys.includes(toolName)) {
        isShowSealBtnBox = true;
      }
    }
    /** 如果为false则隐藏盖章按钮的父级盒子 */
    if (!isShowSealBtnBox) {
      // $("#boxBtnOfSeal").addClass("hidden");
    }
    /** 如果书签和页面功能都不存在，则隐藏侧边菜单 */
    if (
      toolsExcludes.includes("bookMark") === false &&
      toolsExcludes.includes("thumbnail") === false
    ) {
      $("#siderMenuBar").addClass("hidden");
      $("#outerContainer").removeClass("sidebarOpen");
    }
    /** 是否可查看电子印章的详情信息 */
    if (toolsExcludes.includes("signatureDetail")) {
      $("#viewer").removeClass("disabledSignatureDetail");
    } else {
      $("#viewer").addClass("disabledSignatureDetail");
    }
  },
};
